/*
更新日期：2017、02、09
作者：盛彬
备注信息：
以图片形式显示Mat数据  注意作为基类，函数加virtual修饰以防泄漏
*/
#pragma once
#include "AllHeader.hpp"

#ifndef libTestShow_H
#define libTestShow_H

class libTestShow
{
public:

    virtual int Test_Show(char * _name, AVFrame *_frame);
    virtual int Test_Show(char * _name, Mat _src);
    virtual int Test_Show(int indexname, Mat _src);  //慎用···
    virtual int Test_Show(char * _name, Mat _src, Rect _rect);
    virtual int Test_Show(char * _name, Mat _src, vector<Rect> _rec);
    virtual int Test_Show(int indexname, Mat _src, Size _size);
    virtual int Test_Show(int indexname, Mat _src, Size _size, int _time_);
};

inline int libTestShow::Test_Show(char * _name, AVFrame * _frame)
{
    if (_frame->format != AV_PIX_FMT_BGR24)
    {
        return -1;
    }
    Mat src(Size(_frame->width, _frame->height), CV_8UC3);
    src.data = _frame->data[0];
    src.step = _frame->linesize[0];
    imshow(_name, src);
    waitKey(1);

    return 0;
}

inline int libTestShow::Test_Show(char * _name, Mat _src)
{
    imshow(_name, _src);
    waitKey(1);
    return 0;
}

inline int libTestShow::Test_Show(int indexname, Mat _src)
{
    stringstream ss; 
    ss << indexname;
    imshow(ss.str(), _src);
    waitKey(1);
    ss.str("");
    return 0;
}

inline int libTestShow::Test_Show(char * _name, Mat _src, Rect _rect)
{
    rectangle(_src, _rect, Scalar(255, 255, 255), -1);
    imshow(_name, _src);
    waitKey(1);
    return 0;
}

inline int libTestShow::Test_Show(char * _name, Mat _src, vector<Rect> _rec)
{
    for (Rect _rect : _rec)
    {
        rectangle(_src, _rect, Scalar(255, 255, 255), 2);
    }
    imshow(_name, _src);
    waitKey(1);
    return 0;
}

inline int libTestShow::Test_Show(int indexname, Mat _src, Size _size)
{
    stringstream ss;
    ss << indexname;

    Mat src(_size, CV_8UC3);
    cv::resize(_src, src, _size);

    imshow(ss.str(), src);
    waitKey(1);
    ss.str("");
    return 0;
}

inline int libTestShow::Test_Show(int indexname, Mat _src, Size _size, int _time_)
{
    stringstream ss;
    ss << indexname;

    Mat src(_size, CV_8UC3);
    cv::resize(_src, src, _size);

    imshow(ss.str(), src);
    waitKey(_time_);
    ss.str("");
    return 0;
}

#endif // !libTestShow_H